module Data_Mesh

	integer :: nCellsGlobal
	integer :: nFacesGlobal
	integer :: nPointsGlobal
	integer :: nInternalFacesGlobal

    integer :: nPoints,nCells,nFaces,nInternalFaces,nBoundaryFields ! number of Points, Cells, Faces, InternalFaces,BoundaryFields in mesh
    
	! Coors
	real *8,pointer::meshPoints(:,:)    ! node's coor
	
	real *8,pointer::meshFaceCenters(:,:) ! coord of FaceCenters
	real *8,pointer::meshCellCenters(:,:) ! coord of CellCenters

    ! geometrical factors in cells B and F
	real *8,pointer::Db(:) ! on surface B
	real *8,pointer::Df(:) ! on surface B
	real *8,pointer::DbCells(:) ! on cell

	real *8,pointer::meshSf(:,:)    ! normal vector to face
	real *8,pointer::meshV(:)       ! controll volume
	real *8,pointer::meshVPoints(:) ! node's volume


	! Connectivities
	real *8,pointer::BoundaryFieldFactor(:) ! boundary condition factor ?
	integer,pointer::meshFaces(:,:)     ! connectivities - (4,nFaces) - numbers of Verticies (Points)
	integer,pointer::meshCells(:,:)     ! connectivities - (6,nCells) - numbers of Faces
	integer,allocatable :: Points2Faces(:,:) ! connectivities - (20,nPoints) - numbers of Faces
	integer :: FacesInPointsMax = 20 ! max number of faces in a point
	integer,pointer::meshCellPoints(:,:) ! connectivity between cells and nodes (1:8,nCells)
	
	integer,pointer::opposingNeighbourFaceLabel(:) ! connectivity, number of forward face
	integer,pointer::opposingOwnerFaceLabel(:) ! connectivity, number of backward face
	
	integer,pointer::meshFaceNeighbour(:)   ! connectivity, number of forward cell
	integer,pointer::meshFaceOwner(:)       ! connectivity, number of backward cell
	
	integer,pointer::boundaryMeshSize(:)    ! boundary size ?
	integer,pointer::boundaryMeshStart(:)   ! boundary      ?
	integer,pointer::nodeBoundaryMeshSize(:)
	integer,pointer::nodeBoundaryMeshStart(:)
!	integer,pointer::nodeBoundaryMeshLabel(:) ! list of control volumes on the boundary
	! MPI
	integer,pointer::BoundaryProcessorNumber(:)
	integer,pointer::nodeBoundaryMeshProcessorLabel(:)

	character *50,pointer::boundaryMeshName(:) ! boundary name
	character *20,pointer::boundaryMeshType(:) ! boundary type

    integer,allocatable :: nCellNeighbours(:)
    integer,allocatable :: CellNeighbours(:,:)

    integer,allocatable :: nCell2NeigCells(:)
    integer,allocatable :: Cell2NeigCells(:,:)
    integer,allocatable :: nFace2NeigCells(:)
    integer,allocatable :: Face2NeigCells(:,:)
    integer,allocatable :: nPoint2NeigCells(:)
    integer,allocatable :: Point2NeigCells(:,:)
    
    logical,allocatable :: CellViscousStencil(:)
    logical,allocatable :: FaceViscousStencil(:)
    logical,allocatable :: PointViscousStencil(:)

    type tCellStencil
        integer :: nCells = 0
        integer,allocatable :: iCell(:)
        integer :: nFaces = 0
        integer,allocatable :: iFace(:)
        logical,allocatable :: InternalFace(:)
!        integer :: iPoint(8)
        integer,allocatable :: FaceOwner(:)
        integer,allocatable :: FaceNeighbour(:)
        integer,allocatable :: nFace2Point(:)
        integer,allocatable :: Face2Point(:,:)
    end type tCellStencil

    type(tCellStencil),allocatable :: CellStencil(:)


end module Data_Mesh